package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.common.anno.Logs;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/10/13 17:39
 */
@RestController
@RequestMapping("/clues")
@SuppressWarnings("all")
public class ClueController {
    @Autowired
    private ClueService clueService;

    @GetMapping("/pool")
    public Result getCluePool(CluePoolPageDTO dto) {
        return Result.success(clueService.cluePoolList(dto));
    }

    @Logs("将线索转换为无效线索")
    @PutMapping("/false/{id}")
    public Result toFalseClue(@PathVariable Integer id, @RequestBody ClueFalseDTO dto) {
        clueService.toFalseClue(id, dto);
        return Result.success();
    }

    @Logs("新增线索")
    @PostMapping
    public Result createClue(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
        return Result.success();
    }

    @GetMapping
    public Result getAllClues(CluePageDTO dto) {
        return Result.success(clueService.clueListMP(dto));
    }

    @Logs("分配线索")
    @PutMapping("/assign/{clueId}/{userId}")
    public Result assignClue(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder().id(clueId).userId(userId).updateTime(LocalDateTime.now()).status(ClueStatusConstants.CLUE_STATUS_FOLLOWED).build());
        return Result.success();
    }

    @Logs("根据ID查询线索详情")
    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id) {
        return Result.success(clueService.getClueInfoById(id));
    }

    @Logs("更新线索信息")
    @PutMapping
    public Result updateClue(@RequestBody UpdateClueInfoDTO dto) {
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @Logs("将线索转换为商机")
    @PutMapping("/toBusiness/{clueId}")
    public Result toBusiness(@PathVariable Integer clueId) {
        clueService.toBusiness(clueId);
        return Result.success();
    }
}
